package com.atstudy.file;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/28 14:47
 * @copyright: 博为峰
 */
public class FileReaderDemo {
    public static void main(String[] args) throws IOException {
//        m1();
        //abcdef
        FileReader fileReader = new FileReader("C:\\Users\\admin\\Desktop\\java29\\io\\f01.txt");
        char[] chars = new char[2];
        int r = 0;
        while ((r = fileReader.read(chars)) != -1) {//读取的字符数
            String str = new String(chars, 0, r);
            System.out.println(str);
        }
        fileReader.close();
    }

    private static void m1() throws IOException {
        //abcdef
        FileReader fileReader = new FileReader("C:\\Users\\admin\\Desktop\\java29\\io\\f01.txt");
        /*int r1 = fileReader.read();
        System.out.println(r1);
        System.out.println((char) r1);

        int r2 = fileReader.read();
        System.out.println(r2);
        System.out.println((char) r2);*/
        int r = 0;
        while ((r = fileReader.read()) != -1) {//读取的字符
//            System.out.println(r);
            System.out.print((char) r);
        }
        fileReader.close();
    }
}
